﻿using Microsoft.EntityFrameworkCore;
using System.Runtime.CompilerServices;
using Volo.Abp;
using Volo.Abp.EntityFrameworkCore.Modeling;
using YunDrug.EmployeeAuthorization;

namespace YunDrug.EntityFrameworkCore
{
    public static class YunDrugDbContextModelCreatingExtensions
    {
        public static void ConfigureYunDrug(this ModelBuilder builder)
        {
            Check.NotNull(builder, nameof(builder));
            
            builder.Entity<Employee>(b =>
            {
                b.ToTable(YunDrugConsts.DbTablePrefix + "_Employees", YunDrugConsts.DbSchema);
                
                
                b.ConfigureByConvention();
            });
            
            builder.Entity<Role>(b =>
            {
               
                b.ToTable(YunDrugConsts.DbTablePrefix + "_Roles", YunDrugConsts.DbSchema);
              //  b.OwnsMany(p => p.Employees).OwnsMany(p => p.Roles);
                b.ConfigureByConvention();
            });
            builder.Entity<EmployeeConfig>(b =>
            {
                b.ToTable(YunDrugConsts.DbTablePrefix + "_EmployeeConfigs", YunDrugConsts.DbSchema);
                b.ConfigureByConvention();

            });
            builder.Entity<EmployeeRole>(b =>
            {
                b.ToTable(YunDrugConsts.DbTablePrefix + "_EmployeeRoles", YunDrugConsts.DbSchema);
                b.ConfigureByConvention();
            });
            /* Configure your own tables/entities inside here */

            //builder.Entity<YourEntity>(b =>
            //{
            //    b.ToTable(YunDrugConsts.DbTablePrefix + "YourEntities", YunDrugConsts.DbSchema);
            //    b.ConfigureByConvention(); //auto configure for the base class props
            //    //...
            //});
        }
    }
}